package com.bsoft.exchange.controller.detect;

import com.bsoft.exchange.service.DetectService;
import com.bsoft.exchange.util.BaseResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class DetectController {

    private static final Logger log = LoggerFactory.getLogger(DetectController.class);

    @Autowired
    private DetectService detectService;

    @RequestMapping(value = "/detect",method = RequestMethod.POST)
    public BaseResponse<String> insertDetect(@RequestBody Map<String,String> param){
        log.info("======= 核酸检测入参:{} =======",param);
        BaseResponse<String> baseResponse = new BaseResponse<>();
        if(param == null){
            baseResponse.setCode(-100);
            baseResponse.setMessage("参数不能为空！");
            return baseResponse;
        }
        if(StringUtils.isBlank(param.get("patientId"))){
            baseResponse.setCode(-100);
            baseResponse.setMessage("病人id不能为空！");
            return baseResponse;
        }
        if(StringUtils.isBlank(param.get("date"))){
            baseResponse.setCode(-100);
            baseResponse.setMessage("预约时间不能为空！");
            return baseResponse;
        }
        String code = detectService.insertDetect(param.get("patientId"),param.get("date"));
        log.info("======= 核酸检测出参:{} =======",code);
        baseResponse.setMessage("核酸检测开单成功！");
        baseResponse.setCode(200);
        baseResponse.setData(code);
        return baseResponse;
    }
}
